﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace K19T2_T133747_PhucTran_LabAssignment04.Tests
{
    public class CalcAverage
    {
        public float average(int[] value, int minmum, int maxmum)
        {
            int i = 0;
            int inputNumber = 0;
            int validNumber = 0;
            int sum = 0;
            float my_average = 0;

            while ((value[i] != -999) && (inputNumber < 100))
            {
                inputNumber++;
                if ((value[i] >= minmum) && (value[i] <= maxmum))
                {
                    validNumber++;
                    sum = sum + value[i];
                }
                else break;
                i++;
            }

            if (validNumber > 0)
                my_average = sum / validNumber;
            else
                my_average = -999;
            return my_average;
        }
    }
}
